//
//  HZL_NearbyTableViewCell.m
//  B_Project
//
//  Created by 胡佳俊 on 15/12/1.
//  Copyright © 2015年 HZL. All rights reserved.
//

#import "HZL_NearbyTableViewCell.h"
#import "Masonry.h"
#import "HZL_MapViewController.h"
@interface HZL_NearbyTableViewCell ()
@property (nonatomic, strong) UIImageView *coverImgView;
@property (nonatomic, strong) UILabel *nameLabel;
@property (nonatomic, strong) UILabel *descriptionLabel;
@property (nonatomic, strong) UILabel *distancevisited_countLabel;
@property (nonatomic, strong) UIButton *addressBtn;

@end
@implementation HZL_NearbyTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.coverImgView = [[UIImageView alloc] init];
        [self.contentView addSubview:self.coverImgView];
        
        self.nameLabel = [[UILabel alloc] init];
//        self.nameLabel.backgroundColor = [UIColor redColor];
        [self.contentView addSubview:self.nameLabel];
        
        self.descriptionLabel = [[UILabel alloc] init];
//        self.descriptionLabel.backgroundColor = [UIColor cyanColor];
        [self.contentView addSubview:self.descriptionLabel];
        
        self.distancevisited_countLabel = [[UILabel alloc] init];
        [self.contentView addSubview:self.distancevisited_countLabel];
        
        self.addressBtn = [UIButton buttonWithType:UIButtonTypeSystem];
//        self.addressBtn.backgroundColor  = [UIColor orangeColor];
        [self.addressBtn addTarget:self action:@selector(go) forControlEvents:UIControlEventTouchUpInside];
        [self.addressBtn setImage:[UIImage imageNamed:@"iconfont-dizhi"] forState:UIControlStateNormal];
        [self.contentView addSubview:self.addressBtn];
    }
    return self;
}
- (void)layoutSubviews
{
    [super layoutSubviews];
//    self.coverImgView.frame = CGRectMake(10, 10, 100, 100);
    [self.coverImgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.contentView).with.offset(10);
        make.left.mas_equalTo(self.contentView).with.offset(10);
        make.size.mas_equalTo(CGSizeMake(100, 100));
    }];
    [self.nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.contentView).with.offset(10);
        make.right.mas_equalTo(self.contentView).with.offset(-10);
        make.size.mas_equalTo(CGSizeMake(WIDTH - 125, 20));
    }];
    [self.descriptionLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.contentView).with.offset(40);
        make.right.mas_equalTo(self.contentView).with.offset(-10);
        make.size.mas_equalTo(CGSizeMake(WIDTH - 125, 50));
    }];
    self.descriptionLabel.numberOfLines = 0;
    [self.distancevisited_countLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.contentView).with.offset(90);
        make.right.mas_equalTo(self.contentView).with.offset(-35);
        make.size.mas_equalTo(CGSizeMake(WIDTH - 150, 20));
    }];
    [self.addressBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.contentView).with.offset(90);
        make.right.mas_equalTo(self.contentView).with.offset(-15);
        make.size.mas_equalTo(CGSizeMake(20, 20));
    }];
                              
}
- (void)go
{
    self.block(self.model);

}
- (void)setModel:(HZL_NearbyModel *)model
{
    if (_model != model) {
        _model = model;
    }
    [self.coverImgView sd_setImageWithURL:[NSURL URLWithString:model.cover] placeholderImage:nil];
    self.nameLabel.text = model.name;
    self.nameLabel.font = [UIFont boldSystemFontOfSize:18];
    self.descriptionLabel.text = model.description1;
    self.descriptionLabel.font = [UIFont systemFontOfSize:13];
    self.descriptionLabel.textColor = [UIColor grayColor];
//    NSString *str = [NSString stringWithFormat:@"%@", model.distance];
//    self.distancevisited_countLabel.text = [NSString stringWithFormat:@"距我 %@KM / %@ 人去过", [str substringToIndex:5] , model.visited_count];
    self.distancevisited_countLabel.text = [NSString stringWithFormat:@"%@ 人去过", model.visited_count];
    self.distancevisited_countLabel.font = [UIFont systemFontOfSize:13];
    self.distancevisited_countLabel.textColor = [UIColor grayColor];
    
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
